from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext import db
from google.appengine.api import mail
from google.appengine.api import users

class Datastore(db.Model):
    owner = db.StringProperty()
    users = db.StringListProperty()
    provider = db.StringProperty()
    username = db.StringProperty()
    password = db.StringProperty()
    metadata = db.StringListProperty()

class Settings(db.Model):
    user = db.StringProperty()
    reaperlocation = db.StringProperty()
    medialocation = db.StringProperty()
    metadata = db.StringListProperty()

class Song(db.Model):
    title = db.StringProperty()
    owner = db.StringProperty()
    users = db.StringListProperty()
    limitedusers = db.StringListProperty()
    opened = db.StringProperty()
    tracklist = db.StringListProperty()
    metadata = db.StringListProperty()
    lastversion = db.IntegerProperty()
    lastdate = db.DateTimeProperty()
    lastuser = db.StringProperty()
    lastmd5 = db.StringProperty()

class SongVersion(db.Model):
    song = db.ReferenceProperty(Song)
    user = db.StringProperty()
    updatedate = db.DateTimeProperty(auto_now_add=True)
    md5 = db.StringProperty()
    number = db.IntegerProperty()
    content = db.TextProperty()

class Track(db.Model):
    datastore = db.ReferenceProperty(Datastore)
    uploader = db.StringProperty()
    filename = db.StringProperty()
    title = db.StringProperty()
    md5 = db.StringProperty()

class MainHandler(webapp.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user:
            self.response.headers['Content-Type'] = 'text/plain'
            self.response.out.write('Hello, ' + user.nickname())
        else:
            self.redirect(users.create_login_url(self.request.uri))

def main():
    application = webapp.WSGIApplication([('/', MainHandler)],debug=True)
    util.run_wsgi_app(application)

if __name__ == '__main__':
    main()

